package com.suixun.service.credits.impl;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.suixun.dao.credits.CreditTaskMapper;
import com.suixun.entity.credits.CreditTask;
import com.suixun.service.credits.CreditTaskService;
import com.suixun.vo.credits.BaseVo;
import com.suixun.vo.credits.ResponseVo;

/**
 * 可以获取积分的任务列表
 * 
 * @author yh
 * @date 2017年11月15日
 */
@Service
public class CreditTaskServiceImpl implements CreditTaskService {
    
    //可以获取积分的任务列表
    @Autowired
    private CreditTaskMapper taskMapper; 
    
    @Override
    public ResponseVo<BaseVo> findAllName(){
        List<CreditTask> taskList = taskMapper.findAllName();
        if (taskList == null) {
            return null;
        }
        // 根据id排序
        Collections.sort(taskList, new Comparator<CreditTask>() {
            @Override
            public int compare(CreditTask o1, CreditTask o2) {
                return o1.getId().compareTo(o2.getId());
            }
        });
        List<BaseVo> taskListVo = new ArrayList<>();
        for (CreditTask ct : taskList) {
            taskListVo.add(new BaseVo(ct.getId(), ct.getName()));
        }
        return new ResponseVo<>(taskListVo);
    }

}
